package com.work.game.home.ui.activity.agent;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.anythink.nativead.api.ATNativeAdView;
import com.work.game.R;
import com.work.game.ad.MediationFeedAd;
import com.work.game.ad.MediationTablePlaqueAd;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAd;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdProCenter;
import com.work.game.ad.kaku.nativie.TaKuNativeAd;
import com.work.game.ad.kaku.nativie.TaKuNativeAdProCenter;
import com.work.game.home.ui.activity.InviteRecordActivity;
import com.work.game.home.ui.activity.InviteUserActivity;
import com.work.game.home.ui.activity.RewardRecordActivity;
import com.work.game.home.ui.activity.WithdrawalActivity;
import com.work.game.home.ui.enums.MoneyTypeEnum;
import com.work.game.home.ui.enums.RedisEnum;
import com.work.game.volley.BaseActivity;
import com.work.game.volley.state.HUCState;

public class PromotionCenterActivity extends BaseActivity {
    private TextView tvNickname, tvId;

    private TextView tvMoneyGoldCoin, tvMoneyRedPacket, tvExtension;

    private MediationFeedAd mediationFeedAd;
    MediationTablePlaqueAd mediationTablePlaqueAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_promotion_center);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("推广中心");
        tvNickname.setText(getSharedPreferences("nickname"));
        tvId.setText("ID:" + getSharedPreferences("id"));
        initAd();
    }

    @Override
    protected void onResume() {
        super.onResume();
        tvMoneyGoldCoin.setText(getSharedPreferences(MoneyTypeEnum.MONEY_COMMISSION_GOLD_COINS.getKey()));
        tvMoneyRedPacket.setText(getSharedPreferences(MoneyTypeEnum.MONEY_COMMISSION_RED_ENVELOPE.getKey()));
        tvExtension.setText(getSharedPreferences(MoneyTypeEnum.MONEY_EXTENSION_RED_ENVELOPE.getKey()));
    }

    @Override
    public void initView() {
        super.initView();
        tvNickname = findViewById(R.id.tv_nickname);
        tvId = findViewById(R.id.tv_id);
        tvMoneyGoldCoin = findViewById(R.id.tv_moneyGoldCoin);
        tvMoneyRedPacket = findViewById(R.id.tv_moneyRedPacket);
        tvExtension = findViewById(R.id.tv_extension);

    }

    @Override
    public void initClick() {
        super.initClick();
        findViewById(R.id.tv_jb_fy).setOnClickListener(this);
        findViewById(R.id.tv_jb_fy_record).setOnClickListener(this);
        findViewById(R.id.tv_hb_fy).setOnClickListener(this);
        findViewById(R.id.tv_hb_fy_record).setOnClickListener(this);
        findViewById(R.id.tv_tg_hb).setOnClickListener(this);
        findViewById(R.id.tv_tg_hb_record).setOnClickListener(this);
        findViewById(R.id.ll_qrcode).setOnClickListener(this);
        findViewById(R.id.ll_invite_record).setOnClickListener(this);
        findViewById(R.id.ll_data).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.ll_qrcode:
                sendIntent(this, InviteUserActivity.class);
                break;
            case R.id.ll_invite_record:
                sendIntent(this, InviteRecordActivity.class);
                break;
            case R.id.ll_data:
                sendIntent(this, DataCenterActivity.class);
                break;
            case R.id.tv_jb_fy:
                sendIntent(this, WithdrawalActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_3));
                break;
            case R.id.tv_jb_fy_record:
                sendIntent(this, RewardRecordActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_3));
                break;
            case R.id.tv_hb_fy:
                sendIntent(this, WithdrawalActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_4));
                break;
            case R.id.tv_hb_fy_record:
                sendIntent(this, RewardRecordActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_4));
                break;
            case R.id.tv_tg_hb:
                sendIntent(this, WithdrawalActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_5));
                break;
            case R.id.tv_tg_hb_record:
                sendIntent(this, RewardRecordActivity.class, String.valueOf(HUCState.HUC_REQEUST_CODE_5));
                break;
            default:
                break;
        }
    }

    private void initAd() {
        String taKu = getSharedPreferences(RedisEnum.TA_KU.getKey());
        ATNativeAdView flContent = findViewById(R.id.fl_content);
        if (RedisEnum.TA_KU.getValue().equals(taKu)) {
            TaKuInterstitialAdProCenter taKuInterstitialAdProCenter = TaKuInterstitialAdProCenter.getInstance();
            taKuInterstitialAdProCenter.setToken(getSharedPreferences("deviceId"));
            taKuInterstitialAdProCenter.showAd(this);
            //信息流
            TaKuNativeAdProCenter taKuNativeAdProCenter = TaKuNativeAdProCenter.getInstance();
            taKuNativeAdProCenter.setmATNativeAdView(flContent);
            taKuNativeAdProCenter.setToken(getSharedPreferences("deviceId"));
            taKuNativeAdProCenter.showAd();
        } else {
            mediationTablePlaqueAd = MediationTablePlaqueAd.getInstance();
            mediationTablePlaqueAd.showCacheInterstitialFullAd(this, null);
            //信息流
            mediationFeedAd = MediationFeedAd.getInstance();
            mediationFeedAd.setFlFeed(flContent);
            mediationFeedAd.setActivity(this);
            mediationFeedAd.showCacheFeedAd();
        }
    }
}